package util;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class BannerUtil {
    private static InputStream in = null;
    private static InputStreamReader inputStreamReader = null;
    private static BufferedReader reader = null;

    public static void print() {
        try {
            in = BannerUtil.class.getResourceAsStream("/banner.txt");
            inputStreamReader = new InputStreamReader(in);
            reader = new BufferedReader(inputStreamReader);
            String len = null;
            while ((len = reader.readLine()) != null) {
                Thread.sleep(200);
                System.out.println(len);
            }
        } catch (Exception e) {
            System.out.println("打印失败");
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (inputStreamReader != null) {
                try {
                    inputStreamReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }

    public static void printStr(JTextArea area) {
        try {
            in = BannerUtil.class.getResourceAsStream("/banner02.txt");
            inputStreamReader = new InputStreamReader(in,"UTF-8");
            reader = new BufferedReader(inputStreamReader);

            String len = null;
            while ((len = reader.readLine()) != null) {
                area.append(len);
                Thread.sleep(150);
                area.append("\n");
            }
        } catch (Exception e) {
            System.out.println("打印失败");
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (inputStreamReader != null) {
                try {
                    inputStreamReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
